﻿using System;
using COC.Algorithm;
using COC.Character;
using UnityEngine;
using System.Collections;

public class ObjectPoolTest : BaseBehaviourSupport
{
    public PoolManager<String, Component> objsPoolManager;
    DateTime startTime;
    TimeSpan consumedTime;
    bool moveCamera;
    Color color = new Color(.114f, .319f, .255f, .9f);
    Color color3 = new Color(.614f, .619f, .655f, .5f);
    Color color2 = new Color(.614f, .719f, .255f, .9f);
    Color color4 = new Color(.994f, .990f, .825f, .5f);
    Color color5 = new Color(.914f, .561f, .145f, .6f);
    Color color6 = new Color(.1014f, .971f, .255f, .5f);
    // Use this for initialization
    void Awake()
    {
        objsPoolManager = ObjectPool.getInstance();
        for (int j = 0; j < 20; j++)
        {
            objsPoolManager.addPrefab("Cube", GameObject.CreatePrimitive(PrimitiveType.Cube).transform);
           // objsPoolManager.Recycle("Cube",GameObject.CreatePrimitive(PrimitiveType.Cube));

        }
        Component c=null;
        int index = 0;
        startTime = System.DateTime.Now;
        for (int i=0; i < 9000; i++)
        {
            index++;
            c=objsPoolManager.Spawn("Cube",new Vector3(10.1f*i,0.2f,i));
            c.transform.parent = this.transform;
            c.transform.localScale=new Vector3(5.0f,5.0f,5.0f);
            c.gameObject.renderer.material.color = Color.Lerp(color, color2, 3.0f * Time.deltaTime*i); ;
            //c.transform.localPosition = Vector3.left * 1;
          //  objsPoolManager.Recycle("Cube",c);
        }
        consumedTime=System.DateTime.Now-startTime;
        Debug.Log("finished time:"+String.Format("{0}.{1}", consumedTime.Seconds, consumedTime.Milliseconds.ToString().PadLeft(3, '0'))+" s");
        Debug.Log("------POOL OBJECTS COUNT:---------:"+objsPoolManager.count("Cube")+" Already handled:"+index);
        moveCamera = true;

    }


    // Update is called once per frame
    void Update()
    {
        if (moveCamera)
            if(this.transform.localPosition.z<9000*2*10)
                Camera.main.transform.localPosition+= Vector3.right * Time.fixedDeltaTime * 20.0f;
    }
}
